
package com.bangcommunity.bbframe.druid.filter.qtmonitor;

import com.alibaba.druid.filter.AutoLoad;
import com.alibaba.druid.filter.stat.StatFilterContextListenerAdapter;
import com.bangcommunity.bbframe.mlog.logger.MLogFacade;

/**
 * Created by tanghc on 17/1/16.
 */
@AutoLoad
public class QtmonitorContextListener extends StatFilterContextListenerAdapter {
    private static final String monitor_key = "druid";

    @Override
    public void addUpdateCount(int updateCount) {
        if (MLogFacade.isMLogTraceEnable()) {
            MLogFacade.trace("updateCount={}", updateCount);
        }
    }

    @Override
    public void addFetchRowCount(int fetchRowCount) {

        if (MLogFacade.isMLogTraceEnable()) {
            MLogFacade.trace("fetchRowCount={}", fetchRowCount);
        }
    }

    @Override
    public void executeBefore(String sql, boolean inTransaction) {

        if (MLogFacade.isMLogTraceEnable()) {
            MLogFacade.trace("executeBefore:sql={},inTransaction={}", sql, inTransaction);
        }
    }

    @Override
    public void executeAfter(String sql, long nanos, Throwable error) {

        if (MLogFacade.isMLogTraceEnable()) {
            MLogFacade.trace("executeAfter:sql={},nanos={},error={}", sql, nanos, error);
        }
    }

    @Override
    public void commit() {

        if (MLogFacade.isMLogTraceEnable()) {
            MLogFacade.trace("commit");
        }
    }

    @Override
    public void rollback() {

        if (MLogFacade.isMLogTraceEnable()) {
            MLogFacade.trace("rollback");
        }
    }

    @Override
    public void pool_connect() {

        if (MLogFacade.isMLogTraceEnable()) {
            MLogFacade.trace("pool_connect");
        }
    }

    @Override
    public void pool_close(long nanos) {

        if (MLogFacade.isMLogTraceEnable()) {
            MLogFacade.trace("pool_close");
        }
    }

    @Override
    public void resultSet_open() {

        if (MLogFacade.isMLogTraceEnable()) {
            MLogFacade.trace("resultSet_open");
        }
    }

    @Override
    public void resultSet_close(long nanos) {

        if (MLogFacade.isMLogTraceEnable()) {
            MLogFacade.trace("resultSet_close:nanos={}", nanos);
        }
    }
}
